//
//  algori.cpp
//  SAO
//
//  Created by なな on 2017/10/25.
//  Copyright © 2017年 なな. All rights reserved.
//

#include "algori.hpp"
solution::solution(){}
bool solution::IsPopOrder(vector<int> pushV,vector<int> popV) {
    if(pushV.size() == 0) return false;
    vector<int> stack;
    for(int i = 0,j = 0 ;i < pushV.size();){
        stack.push_back(pushV[i++]);
        while(j < popV.size() && stack.back() == popV[j]){
            stack.pop_back();
            j++;
        }
    }
    return stack.empty();
}

int solution::GetUglyNumber_Solution(int index) {
    if (index < 7)return index;
    vector<int> res(index);
    res[0] = 1;
    int t2 = 0, t3 = 0, t5 = 0, i;
    for (i = 1; i < index; ++i)
    {
        res[i] = min(res[t2] * 2, min(res[t3] * 3, res[t5] * 5));
        if (res[i] == res[t2] * 2)t2++;
        if (res[i] == res[t3] * 3)t3++;
        if (res[i] == res[t5] * 5)t5++;
    }
    return res[index - 1];
}
